<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 传统面向对象 继承
        // [1,2,3]
        class MovieCollection extends Array {
            constructor(name,...items) { // reset
                super(...items)// 父类构造器 展开运算符
                this.name = name;
            }
            add(movie) {
                this.push(movie)
                console.log(this)
            }
            topRated(limit = 10) {
                return this.sort((a,b)=>a.star-b.star).slice(0,limit)
            }
        }
        const movie =new MovieCollection(`wes\'s fav movies`,
        {name:'Bee movie',star:10},
        {name:'star wars trek',star:1},
        {name:'virgin suicides',star:7},
        {name:'king of the road',star:8},
        )
        movie.add({name:'战狼',star:9});
        console.log(movie.topRated(3));
    </script>
</body>
</html>